<?php
/**
 * Created by PhpStorm.
 * User: HHZ
 * Date: 2018/12/18
 * Time: 16:22
 */

namespace Biz\service\activity;

use Biz\model\activity\ShopGreyList as mShopGreyList;
use Biz\model\ShopBasicInfo as mShopBasicInfo;

/**
 * @deprecated
 */
class ShopGreyList
{
    /**
     * 商家活动灰名单列表页
     * @return array
     */
    public static function admShopGreyList()
    {
        $shopGreyList = mShopGreyList::select('*', [
            'AND' => [
                'status' => mShopGreyList::STATUS_NORMAL
            ],
            'ORDER' => ['id' => 'DESC']
        ]);

        return ['list' => $shopGreyList, 'total' => mShopGreyList::count('*', [ 'status' => mShopGreyList::STATUS_NORMAL])];
    }

    /**
     * 从灰名单中删除某一个商家
     * @param $id
     * @param $adminId
     * @return mixed
     */
    public static function delShopGreyList($id, $adminId)
    {
        return mShopGreyList::update(['status' => mShopGreyList::STATUS_DELETE, 'admin_id' => $adminId], [
            'id' => $id
        ])->rowCount();
    }

    /**
     * 添加商家到灰名单
     * @param $shopIds
     * @param $adminId
     * @return bool
     */
    public static function addShopGreyList($shopIds, $adminId)
    {
        $shopIdList  = mShopBasicInfo::select('shop_id');
        $diffShopIds = array_diff($shopIds, $shopIdList);
        if($diffShopIds) {
            return false;
        }

        $list = [];
        foreach ($shopIds as $shopId) {
            $list[] = [
                'shop_id' => $shopId,
                'addtime' => date('Y-m-d H:i:s'),
                'edittime' => date('Y-m-d H:i:s'),
                'admin_id' => $adminId,
                'status' => mShopGreyList::STATUS_NORMAL
            ];
        }

        return mShopGreyList::insert($list)->rowCount();
    }
}